/*0sv6NJsBl1XywJ+fpMKzpQQ0qSvrdIQatKioOfCJ8wRenkDf0o+OoAB60KDYgUrE*/
/*
 * @Descripttion:
 * @version:
 * @Author: Chendch
 * @Date: 2020-10-16 09:58:07
 * @LastEditors: Chendch
 * @LastEditTime: 2021-09-15 10:23:46
 */
import React, {Component, Fragment} from "react";
import {dataSource} from "../CONSTANCE";
import { base, high, ajax, toast, pageTo } from 'nc-lightapp-front';
import SupTemplate from '../../../../public/pubComponent/datatemplet/importTempletDlg';
import ExcelOutput from 'uap/common/components/ExcelOutput';
import AssignStepDialog from '../../assign/AssignStepDialog'; //向导分配
import BatchUpdateWarzid from '../../batchedit/BatchUpdateWarzidPage'; //重构后的向导批改
import AttachmentMng from '../../component/AttachmentMng'; //附件管理
import DeleteDialogWapper from '../../component/DeleteDialogWapper';
import DialogWapper from '../../component/DialogWapper';

import SupBrowseOrgDoc from '../../component/SupBrowseOrgDoc'; //查看组织档案
// import Transfer from '../../../Transfer';
import Transfer from '../../../../../uap/public/excomponents/Transfer';
import { getDialogConfig ,querySupplierVersion} from '../../utils/SupplierUtils';
const {NCAffix,NCDiv, NCRadio, NCTabsControl} = base;
const {PrintOutput}=high;

export default function draw() {
    const {tabList = [], status, card, showBasicTabChild, activeTab, activeChildCode, tabChildList, currMainCode, activeChildTab} = this.state,
        {button ,form,cardPagination, BillHeadInfo, ncmodal, editTable} = this.props,
        {createBillHeadInfo} = BillHeadInfo, //新加 返回图标和按钮
        {createCardPagination} = cardPagination,
        {createForm} = form,
        { createButtonApp} = button,
        {createModal} = ncmodal,
        {createEditTable} = editTable;
    let title = this.props.nodeType == 'GLOBE_NODE'?this.Lang['10140SUG-000186']:(this.props.nodeType=='GROUP_NODE'?this.Lang['10140SUG-000187']:this.Lang['10140SUG-000188']);
    let browseStatus = status =='browse' || status == 'edit_cancel' || status =='add_cancel' || !status;
    return(
        card && <div  className='uapbd-supplier-card'>
            <div>
                <NCAffix>
                    <NCDiv areaCode={NCDiv.config.HEADER} className='nc-bill-header-area'>
                        {/* 应测试部要求，为了自动化测试必须替换成平台的createBillHeadInfo */}
                        <div className='header-title-search-area'>
                            {createBillHeadInfo({
                                    title,
                                    backBtnClick: this.onCardButtonClick.bind(this,this.props,'Card_Return'),
                                    showBackBtn:browseStatus,
                                    initShowBackBtn:browseStatus
                                }
                            )}
                        </div>
                        <div className="header-button-area">
                            {createButtonApp(card.buttonConfig)}
                        </div>
                        {isRenderCardPagination.call(this)?
                            <div className='header-cardPagination-area'>
                                {createCardPagination({
                                    handlePageInfoChange: this.handleCardPagination,
                                    dataSource:dataSource})}
                            </div>
                            :null

                        }
                    </NCDiv>
                </NCAffix>
                <div className="nc-bill-form-area nc-theme-gray-area-bgc gray-contain">
                    {createForm(card.form.baseFormId, card.form.action)}
                </div>
                {/* 渲染多页签位置 */}
                <div className="section-contain nc-theme-area-bgc">
                    {this.addCardTableOperateField()}
                    <NCTabsControl defaultKey={activeTab}>
                        {tabList.map( item => {
                            return <div key={item.k} clickFun={this.onTabChange.bind(this, "supplier_baseInfo_card", item.k)}>
                                {item.title}
                            </div>
                        })}
                    </NCTabsControl>
                    {/* 基本信息 */}
                    {currMainCode == "supplier_baseInfo_card" ? <section className="nc-bill-form-area supplier-card-contain nc-theme-gray-area-bgc">
                        {createForm(card.form.formId, card.form.action)}
                    </section> : null}
                    {/* 财务信息 */}
                    {currMainCode == "finance" ? <section className="supplier-card-contain nc-theme-area-bgc">
                        {createEditTable("finance", {
                            shiwEitIcon: false,
                            showPagination: true,
                            adaptionHeight: true,
                            onTabChange: this.onTabChange,
                            handlePageInfoChange: this.onClickPageInfo.bind(this),
                            ...card.table.finance.property
                        })}
                        {this.addCardTableButton.call(this,'finance')}
                    </section> : null}
                    {/* 采购信息 */}
                    {currMainCode == "purchase" ? <section className="supplier-card-contain nc-theme-area-bgc">
                        {createEditTable("purchase", {
                            shiwEitIcon: false,
                            showPagination: true,
                            adaptionHeight: true,
                            onTabChange: this.onTabChange,
                            handlePageInfoChange: this.onClickPageInfo.bind(this),
                            ...card.table.purchase.property
                        })}
                        {this.addCardTableButton.call(this,'purchase')}
                    </section> : null}
                    {showBasicTabChild && <section style={{padding: "0 20px"}} className="nc-theme-area-bgc">
                        <NCTabsControl defaultKey={activeChildTab}>
                            {tabChildList.map( item => {
                                return <div key={item.k} clickFun={this.onTabChange.bind(this, "supbankacc", item.k)}>
                                    {item.title}
                                </div>
                            })}
                        </NCTabsControl>
                        {/* 供应商银行账号 */}
                        {activeChildCode == "supbankacc" ? <section className="supplier-card-contain nc-theme-area-bgc">
                            {createEditTable("supbankacc", {
                                adaptionHeight: true,
                                ...card.table.supbankacc.property
                            })}
                            {this.addCardTableButton.call(this,'supbankacc')}
                        </section> : null}
                        {/* 供应商联系人 */}
                        {activeChildCode == "suplinkman" ? <section className="supplier-card-contain nc-theme-area-bgc">
                            {createEditTable("suplinkman", {
                                adaptionHeight: true,
                                ...card.table.suplinkman.property
                            })}
                            {this.addCardTableButton.call(this,'suplinkman')}
                        </section>: null}
                        {/* 供应商国家税类 */}
                        {activeChildCode == "supcountrytaxes" ? <section className="supplier-card-contain nc-theme-area-bgc">
                            {createEditTable("supcountrytaxes", {
                                adaptionHeight: true,
                                ...card.table.supcountrytaxes.property
                            })}
                            {this.addCardTableButton.call(this,'supcountrytaxes')}
                        </section>: null}
                    </section>}
                </div>

            </div>

            {/* 模板按钮 */}
            {this.state.envParam && <SupTemplate {...Object.assign(this.props,{
                config:{
                    loadData:true,
                    appcode:pageTo.getAppCode(),
                    pagecode:this.props.pagecode,
                    formId:card.form.formId,
                    baseFormId: card.form.baseFormId,
                    subGrid2:card.table.suplinkman.tableId,
                    subGrid3:card.table.supcountrytaxes.tableId,
                    pk_curOrg:this.state.envParam.pk_org,
                    nodeType:this.props.nodeType
                }},{json:this.Lang})} ref={(SupTemplate)=>{this.SupTemplate=SupTemplate;}}/>}

            {/* 向导批改 */}
            {this.state.batchUpdateStepClick && <BatchUpdateWarzid
                ref={(BatchUpdateWarzid)=>{this.BatchUpdateWarzid=BatchUpdateWarzid}}
                {...Object.assign(this.props,
                    {envParam:this.state.envParam,Lang:this.Lang},
                    {listener:{onBeforeSureClick:(callback)=>{
                        callback && callback();
                        let me = this;
                        me.initPageData(me.setCardValue,me.setCardStatus, null, undefined, undefined, undefined, true)}
                    }})}/>}
            {/* 向导分配 */}
            {this.state.assignStepClick && <AssignStepDialog ref={(AssignStepDialog)=>{this.AssignStepDialog=AssignStepDialog;}}
                {...Object.assign(this.props,
                    {envParam:this.state.envParam,Lang:this.Lang},
                    {listener: {onAfterSureClick: (callback) => {
                        callback && callback();
                        let me = this;
                        me.initPageData(me.setCardValue,me.setCardStatus, null, undefined, undefined, undefined, true)}
                    }}
                )} />}

            {ReactDOM.createPortal(this.state.openDialog?<DialogWapper Lang={this.Lang} ref={(Dialog)=>{this.Dialog=Dialog;}}/>:null,document.body)}
            {/* 删除Dialog*/}
            {this.state.openDeleteDialog && ReactDOM.createPortal(<DeleteDialogWapper {...Object.assign(getDialogConfig.call(this,'DeleteDialog'),{Lang:this.Lang})} ref={(DeleteDialog)=>{this.DeleteDialog=DeleteDialog;}}/>,document.body)}
            <AttachmentMng  {...{Lang:this.Lang}} ref={(Attachment)=>{this.Attachment=Attachment;}}/>
            {/* 打印输出 */}
            {drawOutputComp.call(this)}
            <ExcelOutput
                {...Object.assign(this.props)}
                moduleName = 'uapbd'//模块名
                moduleId = 'supplierExcel'
                billType = {this.state.billType}//单据类型
                selectedPKS = {[]}
                appcode={pageTo.getAppCode()}
                pagecode={this.props.pagecode}
            />
            {createModal('createVersion', {//版本化
                color:'success', // 值： "success"/"info"/"warning"/"danger"
                title:this.Lang['10140SUG-000252'],//版本化
                content: <div>
                    {createForm("versionList_card", {})}
                    {createEditTable("versionList", {
                        onRowDoubleClick: onVerDoubleClick.bind(this)
                    })}
                </div>,
                leftBtnName:this.Lang['10140SUG-000253'], //创建新版本
                rightBtnName:this.Lang['10140SUG-000254'], //关闭
                hasCloseBtn:false,//控制“X”按钮，显示true，不显示false，默认不显示
                userControl: true,
                cancelBtnClick:()=>{
                    this.props.modal.close('createVersion');
                },
                beSureBtnClick: this.canCreateVersion,
            })}
            {/* 版本化卡片 */}
            {createModal('versionCardmodal', {
                className: "versionCardmodal",
                title:this.Lang['10140SUG-000255'],//'版本化卡片'
                zIndex: 20002,
                content: <div>
                    {createForm("versionCard", {})}
                </div>
            })}
            {createModal('modal')}
            {/* 实体分配组织 */}
            {createModal('SubjectOrgModal', {
                color: 'success', // 值： "success"/"info"/"warning"/"danger"
                title: this.Lang["10140SUG-000242"],//'关联组织',
                zIndex: 100000,
                content: orgModal.call(this),
                leftBtnName: this.Lang["beSureBtnName-001"],//'确定', //左侧按钮名称
                rightBtnName: this.Lang["cancelBtnName-001"],//'取消', //右侧按钮名称
                hasCloseBtn: false,//控制“X”按钮，显示true，不显示false，默认不显示
                beSureBtnClick: () => {
                    let data = {
                        "treeData": this.state.rightTree,
                        "phone": this.state.curPhone,
                        "type": 1
                    }
                    let _this = this;
                    ajax({
                        url: '/nccloud/baseapp/mobile/assignorg.do',
                        data: data,
                        success: (res) => {
                            const {success,data} = res;
                            if(!success) return ;
                            this.refreshOrg();
                        },
                        error: (msg) => {
                            toast({ content: msg.message, color: 'danger' });
                        }
                    });
                },
            })}
        </div>
    )
}
// 版本化 表格双击
function onVerDoubleClick(record, index, props){
    props.modal.show('versionCardmodal')
    querySupplierVersion(record, index, props)
}

/**
 * 渲染卡片分页组件
 */
function isRenderCardPagination() {
    let {openCard,status,selectedRecords} = this.state;
    return status == 'browse'
        || status == 'edit_cancel'
        || (selectedRecords && selectedRecords.length>0 && status == 'add_cancel');
}

/**
 * 渲染输出组件
 */
function drawOutputComp(){
    return(
        <PrintOutput
            ref='printOutput'
            url={this.state.printUrl}
            data={{
                funcode:pageTo.getAppCode(),//应用的appcode
                nodekey:this.state.printNodeKey,  //需要与数据库保持一致
                oids: this.state.printPks,//打印的数据主键集合
                outputType: "output"
            }}
        >
        </PrintOutput>
    )
}

/**
 * 供应商联系人分配组织
 * * 节点选中方式   10140SUG-000258
 * "10140SUG-000259": "包含所有下级",
    "10140SUG-000260": "仅自己",
 */
function orgModal() {
    return (
    <div>
        <Transfer
            TransferId={'org_transferid'}
            leftTreeData={this.state.leftTree}
            rightTreeData={this.state.rightTree}
            selectType={this.state.selectType}
            title={{ left: this.Lang['10140SUG-000257'], right: this.Lang['10140SUG-000081'] }}
        />
        <div className="nc-theme-common-font-c" style={{ width: '100%', border: '1px solid #eee', margin: '3px 0px' }}>
            <span style={{ padding: '8px' }}>{this.Lang['10140SUG-000258']}</span>
            <NCRadio.NCRadioGroup name="selecttype"
                color="danger" selectedValue={this.state.selectType}
                onChange={this.handleChange.bind(this)}
                style={{ 'text-align': 'center', width: '100%' }}>
                <NCRadio value="default" >{this.Lang['10140SUG-000259']}</NCRadio>
                <NCRadio value="onlySelf" >{this.Lang['10140SUG-000260']}</NCRadio>
            </NCRadio.NCRadioGroup>
        </div>
    </div>)

}
/*0sv6NJsBl1XywJ+fpMKzpQQ0qSvrdIQatKioOfCJ8wRenkDf0o+OoAB60KDYgUrE*/
